/*
	Copyright 2008 Jay Elliott

	This file is part of libemath.

	libemath is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	libemath is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with libemath.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "cAlignedBox.h"



bool emath::cAlignedBox::intersects(cAlignedBox other)
{
	//TODO: implement

	cPoint3d MyPoints[8];
	cPoint3d OtherPoints[8];

	GetPoints(MyPoints);
	other.GetPoints(OtherPoints);

	cPoint3d MyMin = pos - ext;
	cPoint3d MyMax = pos + ext;

	cPoint3d OtherMin = other.pos - other.ext;
	cPoint3d OtherMax = other.pos + other.ext;

	for (int i = 0; i < 8; i++)//for each point
	{
		if (MyPoints[i].x <= OtherMax.x && MyPoints[i].x >= OtherMin.x &&
			MyPoints[i].y <= OtherMax.y && MyPoints[i].y >= OtherMin.y &&
			MyPoints[i].z <= OtherMax.z && MyPoints[i].z >= OtherMin.z)
				return true;



		if (OtherPoints[i].x <= MyMax.x && OtherPoints[i].x >= MyMin.x &&
			OtherPoints[i].y <= MyMax.y && OtherPoints[i].y >= MyMin.y &&
			OtherPoints[i].z <= MyMax.z && OtherPoints[i].z >= MyMin.z)
				return true;
	}
	return false;
}

